{{- $share := (.Scratch.Get "params").share | default dict -}}
{{- .Page.Scratch.SetInMap "this" "sharer" true -}}
{{- if $share.enable -}}
    {{- /* 001: Twitter */ -}}
    {{- if $share.Twitter -}}
        <button title="{{ T `shareOn` }} Twitter" data-sharer="twitter" data-url="{{ .Permalink }}" data-title="{{ .Title }}"{{ with .Site.Params.Social.Twitter }} data-via="{{ . }}"{{ end }}{{ with .Params.tags }} data-hashtags="{{ delimit . `,` }}"{{ end }}>
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "twitter") -}}
        </button>
    {{- end -}}

    {{- /* 002: Facebook */ -}}
    {{- if $share.Facebook -}}
        <button title="{{ T `shareOn` }} Facebook" data-sharer="facebook" data-url="{{ .Permalink }}"{{ with .Params.tags }} data-hashtag="{{ index . 0 }}"{{ end }}>
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "facebook") -}}
        </button>
    {{- end -}}

    {{- /* 003: Linkedin */ -}}
    {{- if $share.Linkedin -}}
        <button title="{{ T `shareOn` }} Linkedin" data-sharer="linkedin" data-url="{{ .Permalink }}">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "linkedin") -}}
        </button>
    {{- end -}}

    {{- /* 004: WhatsApp */ -}}
    {{- if $share.Whatsapp -}}
        <button title="{{ T `shareOn` }} WhatsApp" data-sharer="whatsapp" data-url="{{ .Permalink }}" data-title="{{ .Title }}" data-web>
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "whatsapp") -}}
        </button>
    {{- end -}}

    {{- /* 005: Viber */ -}}
    {{- if $share.Viber -}}
        <button title="{{ T `shareOn` }} Viber" data-sharer="viber" data-url="{{ .Permalink }}" data-title="{{ .Title }}">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "viber") -}}
        </button>
    {{- end -}}

    {{- /* 006: Pinterest */ -}}
    {{- if $share.Pinterest -}}
        <button title="{{ T `shareOn` }} Pinterest" data-sharer="pinterest" data-url="{{ .Permalink }}"{{ with .Description }} data-description="{{ . }}"{{ end }}{{ with .Params.featuredImage }} data-image="{{ . }}"{{ end }}>
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "pinterest") -}}
        </button>
    {{- end -}}

    {{- /* 007: Tumblr */ -}}
    {{- if $share.Tumblr -}}
        <button title="{{ T `shareOn` }} Tumblr" data-sharer="tumblr" data-url="{{ .Permalink }}" data-title="{{ .Title }}"{{ with .Description }} data-caption="{{ . }}"{{ end }}{{ with .Params.tags }} data-tags="{{ delimit . `,` }}"{{ end }}>
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "tumblr") -}}
        </button>
    {{- end -}}

    {{- /* 008: Hacker News */ -}}
    {{- if $share.Hackernews -}}
        <button title="{{ T `shareOn` }} Hacker News" data-sharer="hackernews" data-url="{{ .Permalink }}" data-title="{{ .Title }}">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "hacker-news") -}}
        </button>
    {{- end -}}

    {{- /* 009: Reddit */ -}}
    {{- if $share.Reddit -}}
        <button title="{{ T `shareOn` }} Reddit" data-sharer="reddit" data-url="{{ .Permalink }}">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "reddit") -}}
        </button>
    {{- end -}}

    {{- /* 010: VK */ -}}
    {{- if $share.VK -}}
        <button title="{{ T `shareOn` }} VK" data-sharer="vk" data-url="{{ .Permalink }}" data-title="{{ .Title }}"{{ with .Description }} data-caption="{{ . }}"{{ end }}{{ with .Params.featuredImage }} data-image="{{ . }}"{{ end }}>
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "vk") -}}
        </button>
    {{- end -}}

    {{- /* 011: Buffer */ -}}
    {{- if $share.Buffer -}}
        <button title="{{ T `shareOn` }} Buffer" data-sharer="buffer" data-url="{{ .Permalink }}" data-title="{{ .Title }}"{{ with .Site.Params.Social.Twitter }} data-via="{{ . }}"{{ end }}{{ with .Params.featuredImage }} data-picture="{{ . }}"{{ end }}>
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "buffer") -}}
        </button>
    {{- end -}}

    {{- /* 012: Xing */ -}}
    {{- if $share.Xing -}}
        <button title="{{ T `shareOn` }} Xing" data-sharer="xing" data-url="{{ .Permalink }}" data-title="{{ .Title }}">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "xing") -}}
        </button>
    {{- end -}}

    {{- /* 013: Line */ -}}
    {{- if $share.Line -}}
        <button title="{{ T `shareOn` }} Line" data-sharer="line" data-url="{{ .Permalink }}" data-title="{{ .Title }}">
            {{- partial "plugin/simpleicons.html" "line" -}}
        </button>
    {{- end -}}

    {{- /* 014: Instapaper */ -}}
    {{- if $share.Instapaper -}}
        <button title="{{ T `shareOn` }} Instapaper" data-sharer="instapaper" data-url="{{ .Permalink }}" data-title="{{ .Title }}" data-description="{{ .Description }}">
            {{- partial "plugin/simpleicons.html" "instapaper" -}}
        </button>
    {{- end -}}

    {{- /* 015: Pocket */ -}}
    {{- if $share.Pocket -}}
        <button title="{{ T `shareOn` }} Pocket" data-sharer="pocket" data-url="{{ .Permalink }}">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "get-pocket") -}}
        </button>
    {{- end -}}

    {{- /* 016: Digg */ -}}
    {{- if $share.Digg -}}
        <button title="{{ T `shareOn` }} Digg" data-sharer="digg" data-url="{{ .Permalink }}">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "digg") -}}
        </button>
    {{- end -}}

    {{- /* 017: StumbleUpon */ -}}
    {{- if $share.Stumbleupon -}}
        <button title="{{ T `shareOn` }} StumbleUpon" data-sharer="stumbleupon" data-url="{{ .Permalink }}" data-title="{{ .Title }}">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "stumbleupon") -}}
        </button>
    {{- end -}}

    {{- /* 018: Flipboard */ -}}
    {{- if $share.Flipboard -}}
        <button title="{{ T `shareOn` }} Flipboard" data-sharer="flipboard" data-url="{{ .Permalink }}" data-title="{{ .Title }}">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "flipboard") -}}
        </button>
    {{- end -}}

    {{- /* 019: 微博 */ -}}
    {{- if $share.Weibo -}}
        <button title="{{ T `shareOn` }} 微博" data-sharer="weibo" data-url="{{ .Permalink }}" data-title="{{ .Title }}"{{ with .Params.featuredImage }} data-image="{{ . }}"{{ end }}{{ with .Site.Params.Social.Weibo }} data-ralateuid="{{ . }}"{{ end }}>
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "weibo") -}}
        </button>
    {{- end -}}

    {{- /* 020: 人人 */ -}}
    {{- if $share.Renren -}}
        <button title="{{ T `shareOn` }} 人人" data-sharer="renren" data-url="{{ .Permalink }}">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "renren") -}}
        </button>
    {{- end -}}

    {{- /* 021: Myspace */ -}}
    {{- if $share.Myspace -}}
        <button title="{{ T `shareOn` }} Myspace" data-sharer="myspace" data-url="{{ .Permalink }}" data-title="{{ .Title }}" data-description="{{ .Description }}">
            {{- partial "plugin/simpleicons.html" "myspace" -}}
        </button>
    {{- end -}}

    {{- /* 022: Blogger */ -}}
    {{- if $share.Blogger -}}
        <button title="{{ T `shareOn` }} Blogger" data-sharer="blogger" data-url="{{ .Permalink }}" data-title="{{ .Title }}" data-description="{{ .Description }}">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "blogger") -}}
        </button>
    {{- end -}}

    {{- /* 023: 百度 */ -}}
    {{- if $share.Baidu -}}
        <button title="{{ T `shareOn` }} 百度" data-sharer="baidu" data-url="{{ .Permalink }}" data-title="{{ .Title }}">
            {{- partial "plugin/simpleicons.html" "baidu" -}}
        </button>
    {{- end -}}

    {{- /* 024: OK.RU */ -}}
    {{- if $share.Odnoklassniki -}}
        <button title="{{ T `shareOn` }} OK.RU" data-sharer="okru" data-url="{{ .Permalink }}" data-title="{{ .Title }}">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "odnoklassniki") -}}
        </button>
    {{- end -}}

    {{- /* 025: Evernote */ -}}
    {{- if $share.Evernote -}}
        <button title="{{ T `shareOn` }} Evernote" data-sharer="evernote" data-url="{{ .Permalink }}" data-title="{{ .Title }}">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "evernote") -}}
        </button>
    {{- end -}}

    {{- /* 026: Skype */ -}}
    {{- if $share.Skype -}}
        <button title="{{ T `shareOn` }} Skype" data-sharer="skype" data-url="{{ .Permalink }}" data-title="{{ .Title }}">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "skype") -}}
        </button>
    {{- end -}}

    {{- /* 027: Trello */ -}}
    {{- if $share.Trello -}}
        <button title="{{ T `shareOn` }} Trello" data-sharer="trello" data-url="{{ .Permalink }}" data-title="{{ .Title }}" data-description="{{ .Description }}">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "trello") -}}
        </button>
    {{- end -}}

    {{- /* 028: Mix */ -}}
    {{- if $share.Mix -}}
        <a href="//mix.com/add?url={{ .Permalink }}&amp;description={{ .Title }}" target="_blank" title="{{ T `shareOn` }} Mix">
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "mix") -}}
        </a>
    {{- end -}}

    {{- /* 029: Telegram */ -}}
    {{- if $share.Telegram -}}
        <button title="{{ T `shareOn` }} Telegram" data-sharer="telegram" data-url="{{ .Permalink }}" data-title="{{ .Title }}" data-web>
            {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "telegram-plane") -}}
        </button>
    {{- end -}} 
    
   {{- /* 030: Weixin */ -}}
    {{- if $share.Weixin -}}
    <button class="weixin" title="{{ T `shareOn` }} 微信" data-sharer="weixin" data-url="{{ .Permalink }}" data-title="{{ .Title }}" data-web>
        {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "weixin") -}}
        <img src="{{ $share.Weixin }}{{ .Permalink | safeURL }}" title="{{ .Title }}">
    </button>
    {{- end -}}

    {{- /* 031: Mastodon */ -}}
    {{- if $share.Mastodon -}}
    <script>
        function shareOnMastodon(title, link) {
            const SHARE_MASTODON_DOMAIN = "share_mastodon_domain"
            const savedDomain = localStorage.getItem(SHARE_MASTODON_DOMAIN) ?? "mastodon.social";
            const domain = prompt("Enter your Mastodon domain", savedDomain);
            if (domain === null) {
                return;
            }
            localStorage.setItem(SHARE_MASTODON_DOMAIN, domain)
            const text = title + "\n\n" + link;
            const url = new URL("https://" + domain)
            url.pathname = "share"
            url.searchParams.append('text', text)
            window.open(url, '_blank', "width=500,height=500,left=500,toolbar=0,status=0");
        }
    </script>
    <button title="{{ T `shareOn` }} Mastodon"onclick="javascript:shareOnMastodon({{ .Title }}, {{ .Permalink }})">
        {{- partial "plugin/fontawesome.html" (dict "Style" "brands" "Icon" "mastodon") -}}
    </button>
    {{- end -}}
{{- end -}}
